<script setup lang="ts">
import { ref } from 'vue'
// 导入 lynn-utils 的功能
import { hello, MyButton, useCounter } from 'lynn-utils'

// 测试 hello 函数
const userName = ref('Lynn')
const greeting = ref('')

const testHelloFunction = () => {
  greeting.value = hello(userName.value)
}

// 测试 useCounter composable
const { count, increment, decrement, reset, isEven, isOdd } = useCounter(0)

// 测试 MyButton 组件的点击事件
const handleButtonClick = (event: MouseEvent) => {
  console.log('MyButton clicked!', event)
  alert('MyButton 组件点击成功！')
}
</script>

<template>
  <div class="app-container">
    <h1>Lynn Utils 测试页面</h1>
    
    <!-- 测试 hello 函数 -->
    <section class="test-section">
      <h2>1. 测试 hello 函数</h2>
      <div class="test-content">
        <input v-model="userName" placeholder="输入姓名" />
        <button @click="testHelloFunction">调用 hello 函数</button>
        <p v-if="greeting" class="result">结果: {{ greeting }}</p>
      </div>
    </section>

    <!-- 测试 useCounter composable -->
    <section class="test-section">
      <h2>2. 测试 useCounter composable</h2>
      <div class="test-content">
        <p>当前计数: <strong>{{ count }}</strong></p>
        <p>是偶数: {{ isEven ? '是' : '否' }}</p>
        <p>是奇数: {{ isOdd ? '是' : '否' }}</p>
        <div class="button-group">
          <button @click="increment">增加</button>
          <button @click="decrement">减少</button>
          <button @click="reset">重置</button>
        </div>
      </div>
    </section>

    <!-- 测试 MyButton 组件 -->
    <section class="test-section">
      <h2>3. 测试 MyButton 组件</h2>
      <div class="test-content">
        <div class="button-group">
          <MyButton type="primary" size="small" @click="handleButtonClick">
            Primary Small
          </MyButton>
          <MyButton type="secondary" size="medium" @click="handleButtonClick">
            Secondary Medium
          </MyButton>
          <MyButton type="danger" size="large" @click="handleButtonClick">
            Danger Large
          </MyButton>
          <MyButton type="primary" :disabled="true" @click="handleButtonClick">
            Disabled Button
          </MyButton>
        </div>
      </div>
    </section>
  </div>
</template>

<style scoped>
.app-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
  font-family: Arial, sans-serif;
}

h1 {
  text-align: center;
  color: #2c3e50;
  margin-bottom: 30px;
}

.test-section {
  margin-bottom: 40px;
  padding: 20px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background-color: #f9f9f9;
}

.test-section h2 {
  color: #34495e;
  margin-bottom: 15px;
  border-bottom: 2px solid #3498db;
  padding-bottom: 5px;
}

.test-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.button-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

input {
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
}

button {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  background-color: #3498db;
  color: white;
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.3s;
}

button:hover {
  background-color: #2980b9;
}

button:disabled {
  background-color: #bdc3c7;
  cursor: not-allowed;
}

.result {
  padding: 10px;
  background-color: #e8f5e8;
  border: 1px solid #4caf50;
  border-radius: 4px;
  color: #2e7d32;
  font-weight: bold;
}

p {
  margin: 5px 0;
}

strong {
  color: #e74c3c;
  font-size: 18px;
}
</style>
